package com.jzo2o.customer.controller.open;

import com.jzo2o.api.publics.SmsCodeApi;
import com.jzo2o.api.publics.dto.response.BooleanResDTO;
import com.jzo2o.common.constants.UserType;
import com.jzo2o.common.enums.SmsBussinessTypeEnum;
import com.jzo2o.common.expcetions.BadRequestException;
import com.jzo2o.customer.model.Result.ApiResponse;
import com.jzo2o.customer.model.dto.request.InstitutionRegisterReqDTO;
import com.jzo2o.customer.service.IServeProviderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * \* User: chy
 * \* Date: 2025/9/26  11:21
 * \* Description:
 * \
 */
@RestController
@RequestMapping("/open/serve-provider/institution")
@Slf4j
@RequiredArgsConstructor
public class InstitutionRegisterController {
    private final IServeProviderService serveProviderService;
    private final SmsCodeApi smsCodeApi;

    /**
     * 机构注册
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/register")
    public ApiResponse register(@RequestBody InstitutionRegisterReqDTO reqDTO) {
        log.info("机构注册:{}", reqDTO);
        BooleanResDTO booleanResDTO = smsCodeApi.verify(reqDTO.getPhone(), SmsBussinessTypeEnum.INSTITION_REGISTER, reqDTO.getVerifyCode());
        if (!booleanResDTO.getIsSuccess()) {
            throw new BadRequestException("验证码错误，请重新获取");
        }
        serveProviderService.add(reqDTO.getPhone(), UserType.INSTITUTION, reqDTO.getPassword());
        return ApiResponse.success();
    }


}
